// @ts-nocheck
import router from '@system.router';
import BaseParseConfModel from '../../model/baseParseConfImpl/BaseParseConfModel.js';
import LogUtil from '../../common/baseUtil/LogUtil.js';
import runningLock from '@ohos.runningLock';
import prompt from '@ohos.prompt';

let baseParseConfModel = new BaseParseConfModel();
let logUtil = new LogUtil();
let list = [
    {
        "settingIcon": "",
        "settingType": 1,
        "settingAlias": "RunningLockScreen",
        "settingTitle": "",
        "settingValue": "unKnow",
        "settingArrow": "/res/image/ic_settings_arrow.png",
        "settingShowDivider": true
    },
    {
        "settingIcon": "",
        "settingType": 1,
        "settingAlias": "BACKGROUND",
        "settingTitle": "",
        "settingValue": "unKnow",
        "settingArrow": "/res/image/ic_settings_arrow.png",
        "settingShowDivider": true
    },
    {
        "settingIcon": "",
        "settingType": 1,
        "settingAlias": "PROXIMITY_SCREEN_CONTROL",
        "settingTitle": "",
        "settingValue": "unKnow",
        "settingArrow": "/res/image/ic_settings_arrow.png",
        "settingShowDivider": true
    }
]

export default {
    data: {
        isSupportedList: [],
        supportedJsonPath: '/data/app/el1/bundle/public/com.example.powerhap/com.example.entry/assets/power/resources/rawfile/isSupported.json'
    },
    onInit() {
        logUtil.info('isSupportedPage onInit  start:')
        this.isSupportedList = baseParseConfModel.getJsonData(this.supportedJsonPath);
        this.isSupportedList = this.isSupportedList || list
        logUtil.info('isSupportedPage get isSupportedList by json:' + JSON.stringify(this.isSupportedList))
        for (let key in this.isSupportedList) {
            var value = this.isSupportedList[key]
            var settingAlias = value.settingAlias
            value.settingTitle = this.$t('strings.'.concat(settingAlias))
            logUtil.info('isSupportedList[key].settingTitle is' + JSON.stringify(this.isSupportedList[key].settingTitle))
            this.isSupported(key)
            logUtil.info('runningLock.isRunningLockTypeSupported onInit end:')
        }
        logUtil.info('isSupportedPage onInit end:')
    },
    isSupported(num){
        logUtil.info('async isSupported begin :' + num + ' typeof num ' + (typeof value))
        let supported = false
        try {
            supported = runningLock.isSupported(num);
        } catch(error) {
            prompt.showToast({
                message: 'num: ' + num + ' code: ' + error.code + ' msg: ' + error.message,
                duration: 3000,
            });
        }
        if(supported){
            this.isSupportedList[num].settingValue = '支持'
        } else {
            this.isSupportedList[num].settingValue = '不支持'
        }
        logUtil.info(JSON.stringify(this.isSupportedList[num].settingTitle) + 'setting settingValue is:' + JSON.stringify(this.isSupportedList[num].settingValue))
    },
    onclick_isSupported(e) {
        logUtil.info('isSupportedListComponent onclick start: ' + JSON.stringify(e.detail.text.settingAlias))
        if (e.detail.text.settingAlias == 'RunningLockScreen') {
            logUtil.info('RunningLockScreen onclick start: ')
            this.isSupported(0)
        }
        if (e.detail.text.settingAlias == 'BACKGROUND') {
            logUtil.info('BACKGROUND onclick start: ')
            this.isSupported(runningLock.RunningLockType.BACKGROUND)
        }
        if (e.detail.text.settingAlias == 'PROXIMITY_SCREEN_CONTROL') {
            logUtil.info('PROXIMITY_SCREEN_CONTROL onclick start: ')
            this.isSupported(runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL);
        }
    },
    isSupportedPageBack() {
        logUtil.info('isSupportedPage back start:')
        router.back();
        logUtil.info('isSupportedPage back end:')
    },
    onBackPress() {
        logUtil.info('isSupportedPage onBackPress:')
        router.back();
    },
    onCreate() {
        logUtil.info('isSupportedPage onCreate')
    },
    onReady() {
        logUtil.info('isSupportedPage onReady')
    },
    onShow() {
        logUtil.info('isSupportedPage onShow')
    },
    onHide() {
        logUtil.info('isSupportedPage onHide')
    },
    onDestroy() {
        logUtil.info('isSupportedPage onDestroy')
    }
}